package com.tjec.project.system.controller;

import com.tjec.common.constant.Constants;
import com.tjec.common.utils.poi.ExcelUtil;
import com.tjec.framework.aspectj.lang.annotation.Log;
import com.tjec.framework.aspectj.lang.enums.BusinessType;
import com.tjec.framework.web.controller.BaseController;
import com.tjec.framework.web.domain.AjaxResult;
import com.tjec.framework.web.page.TableDataInfo;
import com.tjec.project.system.domain.BmsMdPickupTemplate;
import com.tjec.project.system.service.IBmsMdPickupTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 收资模板Controller
 *
 * @author tjec
 * @date 2020-04-16
 */
@RestController
@RequestMapping("/system/pickupTemplate")
public class BmsMdPickupTemplateController extends BaseController {
    @Value("${template.url}")
    private String url;
    @Value("${template.pickup_template}")
    private String template;


    @Autowired
    private IBmsMdPickupTemplateService bmsMdPickupTemplateService;

    /**
     * 查询收资模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:pickupTemplate:list')")
    @GetMapping("/list")
    public TableDataInfo list(BmsMdPickupTemplate bmsMdPickupTemplate) {
        startPage();
        List<BmsMdPickupTemplate> list = bmsMdPickupTemplateService.selectBmsMdPickupTemplateList(bmsMdPickupTemplate);
        return getDataTable(list);
    }

    /**
     * 导出收资模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:pickupTemplate:export')")
    @Log(title = "收资模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BmsMdPickupTemplate bmsMdPickupTemplate) {
        List<BmsMdPickupTemplate> list = bmsMdPickupTemplateService.selectBmsMdPickupTemplateList(bmsMdPickupTemplate);
        ExcelUtil<BmsMdPickupTemplate> util = new ExcelUtil<BmsMdPickupTemplate>(BmsMdPickupTemplate.class);
        return util.exportExcel(list, "pickupTemplate");
    }

    /**
     * 下载模板文件
     */
    @PreAuthorize("@ss.hasPermi('system:pickupTemplate:export')")
    @Log(title = "下载模板文件", businessType = BusinessType.EXPORT)
    @GetMapping("/exportTemplate")
    public AjaxResult exportTemplate(HttpServletRequest request) {
        Map map = new HashMap<>();
        map.put("url", Constants.RESOURCE_PREFIX + url + "/" + template);
        return AjaxResult.success(map);
    }

    /**
     * 获取收资模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pickupTemplate:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid) {
        return AjaxResult.success(bmsMdPickupTemplateService.selectBmsMdPickupTemplateById(guid));
    }

    /**
     * 新增收资模板
     */
    @PreAuthorize("@ss.hasPermi('system:pickupTemplate:add')")
    @Log(title = "收资模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmsMdPickupTemplate bmsMdPickupTemplate) {
        return toAjax(bmsMdPickupTemplateService.insertBmsMdPickupTemplate(bmsMdPickupTemplate));
    }

    /**
     * 修改收资模板
     */
    @PreAuthorize("@ss.hasPermi('system:pickupTemplate:edit')")
    @Log(title = "收资模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmsMdPickupTemplate bmsMdPickupTemplate) {
        return toAjax(bmsMdPickupTemplateService.updateBmsMdPickupTemplate(bmsMdPickupTemplate));
    }

    /**
     * 删除收资模板
     */
    @PreAuthorize("@ss.hasPermi('system:pickupTemplate:remove')")
    @Log(title = "收资模板", businessType = BusinessType.DELETE)
    @DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids) {
        return toAjax(bmsMdPickupTemplateService.deleteBmsMdPickupTemplateByIds(guids));
    }
}
